<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>将对象转为响应式</title>
</head>
<body>
  <script>
    const obj = {
      name: 'Alan',
      age: 32
    }

    function defineReactive (target, key , value ,enumerable) {
      Object.defineProperty(target, key, {
        configurable: true,
        enumerable: !!enumerable,
        get() {
          return value
        },
        set(newVal) {
          value = newVal
        }
      })
    }
    Object.keys(obj).forEach(key => {
      defineReactive(obj, key, obj[key], 1)
    })
    
  </script>
</body>
</html>